<?php


namespace app\common\model;


use think\Model;

class Setting extends Model
{

    //保存设置
    public static function saveSettings($name, $data)
    {
        //先判断是否存在
        $res = self::where('name', $name)->find();

        if ($res) {
            $res2 = self::where('name', $name)->update([
                'data' => $data
            ]);
        } else {
            $res2 = self::where('name', $name)->insert([
                'name' => $name,
                'data' => $data,
                'add_time' => time()
            ]);
        }
    }

    //获取指定设置
    public static function getSettings($name)
    {
        //获取指定的设置值，不存在就返回null
        $res = self::where('name', $name)->value('data');
        return $res;

    }

    //获取所有的系统设置
    public static function getAllSetting()
    {
        $setting = [
            'logo' => self::where('name', 'logo')->value('data'),                       //首页公告
            'notice' => self::where('name', 'notice')->value('data'),                       //首页公告
            'about_us' => self::where('name', 'about_us')->value('data'),                   //关于我们
            'group_chat_qrcode' => self::where('name', 'group_chat_qrcode')->value('data'), //加入群聊的二维码地址
            'official_account_qrcode' => self::where('name', 'official_account_qrcode')->value('data'),  //关注公众号的二维码
            'app_name' => self::where('name', 'app_name')->value('data'),                   //产品的名字
            'wechat' => self::where('name', 'wechat')->value('data'),                   //产品的名字
            'share_title' => self::where('name', 'share_title')->value('data'),         //分享标题
            'vip_max_link' => self::where('name', 'vip_max_link')->value('data'),         //分享标题
            'user_max_link' => self::where('name', 'user_max_link')->value('data'),         //分享标题
            'content_source_url' => self::where('name', 'content_source_url')->value('data'),         //阅读原文的标题
            'is_real' => self::where('name', 'is_real')->value('data'),         //排行真假数据
            'app_id' => self::where('name', 'app_id')->value('data'),         //appid
            'adv_id' => self::where('name', 'adv_id')->value('data'),         //广告id
            'check_version' => self::where('name', 'check_version')->value('data'),         //当前审核的版本
            'payment_ratio' => self::where('name', 'payment_ratio')->value('data'),         //百分比设置
            'upload_mode' => self::where('name', 'upload_mode')->value('data'),         //视频的上传模式1文件，2.url地址,
            'poster' => self::where('name', 'poster')->value('data'),         //海报的背景图

            'lv_1_share_income_money' => self::where('name', 'lv_1_share_income_money')->value('data'),         //直推会员佣金
            'lv_2_share_income_money' => self::where('name', 'lv_2_share_income_money')->value('data'),         //间推会员佣金

            "high_vip_lv_1_share_income_money" => self::where('name', 'high_vip_lv_1_share_income_money')->value('data'),         //高级会员直推高级会员佣金
            "high_vip_lv_2_share_income_money" => self::where('name', 'high_vip_lv_2_share_income_money')->value('data'),         //高级会员间推高级会员佣金

            'video_share_title' => self::where('name', 'video_share_title')->value('data'),         //间推会员佣金

            'min_take_out_money' => self::where('name', 'min_take_out_money')->value('data'),         //最小的提现金额
            'lv_1_share_type' => self::where('name', 'lv_1_share_type')->value('data'),                          // 1.普通会员只有一级分销 2.普通会员有两级分销
        ];

        //如果没有设置，就给默认值
        if(!$setting['poster'])$setting['poster']='https://lanchong.oss-cn-beijing.aliyuncs.com/douzuanshe/app/poster1.png';

        if(!$setting['video_share_title'])$setting['video_share_title']='点击查看完整视频';

        //直推和间推的返佣
        if(!$setting['lv_1_share_income_money'])$setting['lv_1_share_income_money']=0;
        if(!$setting['lv_2_share_income_money'])$setting['lv_2_share_income_money']=0;

        if(!$setting['high_vip_lv_1_share_income_money'])$setting['high_vip_lv_1_share_income_money']=0;
        if(!$setting['high_vip_lv_2_share_income_money'])$setting['high_vip_lv_2_share_income_money']=0;
        if(!$setting['min_take_out_money'])$setting['min_take_out_money']=0;
        if(!$setting['lv_1_share_type'])$setting['lv_1_share_type']='2';
      return $setting;
    }


}
